package cfig.launcher

import cfig.helper.Helper
import cfig.helper.Helper.Companion.check_call
import cfig.helper.Helper.Companion.deleteIfExists
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class Packer {
    companion object {
        private val log: Logger = LoggerFactory.getLogger(Packer::class.java)
        private val outDir = Helper.prop("workDir")
        fun main(args: Array<String>) {
            "clear.zip".deleteIfExists()
            "new_ota.zip".deleteIfExists()
            log.info("(1/2) Zipping ...")
            "zip -r ../../clear.zip .".check_call(outDir)
            log.info("(2/2) Signing ...")
            val apksigner = "/home/yu/.programs/Android/build-tools/31.0.0/apksigner"
            ("java -Xmx2G -ea " +
                    "-jar $apksigner " +
                    "-w aosp/security/testkey.x509.pem " +
                    " aosp/security/testkey.pk8 " +
                    " clear.zip " +
                    " new_ota.zip").check_call()
        }
    }
}
